<template>
  <div class="home">
    <el-row :gutter="15">
      <el-col :lg="6" :md="12" :xs="24">
        <div class="card">
          <count-sales :top-info="topInfo1" />
        </div>
      </el-col>
      <el-col :lg="6" :md="12" :xs="24">
        <div class="card">
          <count-views :top-info="topInfo2" />
        </div>
      </el-col>
      <el-col :lg="6" :md="12" :xs="24">
        <div class="card">
          <count-paid :top-info="topInfo3" />
        </div>
      </el-col>
      <el-col :lg="6" :md="12" :xs="24">
        <div class="card">
          <count-effect :top-info="topInfo4" />
        </div>
      </el-col>
    </el-row>

    <el-row :gutter="15">
      <el-col :lg="16" :xs="24">
        <div class="card">
          <tab-chart :chart-info="chartInfo" />
        </div>
      </el-col>
      <el-col :lg="8" :xs="24">
        <div class="card">
          <sales-rank :thisrank="thisrank" />
        </div>
      </el-col>
    </el-row>

    <el-row :gutter="15">
      <el-col :lg="12" :sm="24">
        <div class="card card--last">
          <hot-search />
        </div>
      </el-col>
      <el-col :lg="12" :sm="24">
        <div class="card card--last">
          <category-ratio />
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import CategoryRatio from './home/category-ratio'
import CountSales from './home/count-sales'
import CountViews from './home/count-views'
import CountPaid from './home/count-paid'
import CountEffect from './home/count-effect'
import TabChart from './home/tab-chart'
import SalesRank from './home/sales-rank'
import HotSearch from './home/hot-search'
import { mapGetters } from 'vuex'

export default {
  components: {
    CategoryRatio,
    CountSales,
    CountViews,
    CountPaid,
    CountEffect,
    TabChart,
    SalesRank,
    HotSearch
  },
  data() {
    return {
      topInfo1: {
        terminalNum: 233,
        running: 200,
        unrunning: 33
      },
      topInfo2: {
        lockNum: 998,
        using: 890
      },
      topInfo3: {
        useNum: 50,
        wxuseNum: 15,
        serviceuseNum: 35
      },
      topInfo4: {
        workorderNum: 100,
        handled: 80,
        unhandled: 20
      },
      chartInfo: {},
      rank: {},
      terminalOrderList: [],
      thisrank: []
    }
  },
  computed: {
    ...mapGetters([
      'user',
      'name',
      'avatar',
      'roles'
    ])
  },
  created() {
    this.getInfo()
  },

  methods: {
    getInfo() {
      // this.$service.home.getInfo().then((res) => {
      //   console.log('首页数据', res.rank)
      //   this.topInfo1 = res.topInfo.info1
      //   this.topInfo2 = res.topInfo.info2
      //   this.topInfo3 = res.topInfo.info3
      //   this.topInfo4 = res.topInfo.info4

      //   this.chartInfo = res.zhu
      //   this.rank = res.rank
      //   this.terminalOrderList = res.workerOrder.terminalOrderList

      //   let arr = []
      //   for (const key in this.rank) {
      //     arr.push(this.rank[key])
      //   }
      //   arr = arr.sort(this.compare('count'))
      //   arr = arr.reverse()
      //   console.log('this.rank', arr)
      //   this.thisrank = arr
      //   console.log('this.thisrank', this.thisrank)
      // })
    },
    compare(label) {
      return function(a, b) {
        var value1 = a[label]
        var value2 = b[label]
        return value1 - value2
      }
    }
  }
}
</script>

<style lang="scss">
.home {
  background-color: #eee;
  padding: 15px;
  .card {
    background-color: #fff;
    border-radius: 5px;
    margin-bottom: 15px;
    font-size: 12px;
    letter-spacing: 0.5px;

    &__header {
      display: flex;
      align-items: center;
      height: 50px;
      padding: 0 20px;

      .label {
        font-size: 12px;
      }

      .value {
        font-size: 18px;
        font-weight: bold;
        margin-left: 10px;
      }
    }

    &__container {
      padding: 0 20px;
      height: 50px;
    }

    &__footer {
      display: flex;
      align-items: center;
      height: 50px;
      border-top: 1px solid #f7f7f7;
      font-size: 12px;
      margin: 0 5px;
      padding: 0 15px;
      box-sizing: border-box;

      .label {
        margin-right: 10px;
      }

      .value {
        font-size: 13px;
      }
    }
  }
}
</style>
